
package cn.group01.git.service.impl;

import cn.group01.git.mapper.EchartsMapper;
import cn.group01.git.service.EchartsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @description:
 * @author: 张 庆 昌
 * @date: 2023/7/13 9:37
 **/
@Service
public class EchartsServiceImpl implements EchartsService {
    @Autowired
    private EchartsMapper echartsMapper;

    public Map<String, Object> getInportLineData() {

        // 折线图 用Map集合封装数据
        HashMap<String, Object> map = new HashMap<String, Object>();

        // 取year
        List<String> years = echartsMapper.getYear();
        // 将取到的year存入map
        map.put("years",years);

        // 取supName
        List<String> supNames = echartsMapper.getSupName();
        // 将取到的supNames存入map
        map.put("supNames",supNames);

        // 取supName_year

        HashMap<String, Object> supNameYear = new HashMap<String, Object>();
        for (String supName : supNames) {  //供应商1 供应商2 供应商3 。。。。。
            ArrayList<Double> numbers = new ArrayList<Double>();
            for (String year : years) {  // 2019  2020 2021 2022 2023
                Double money =   echartsMapper.getImportTotolMoney(supName,year);// 查year年xx供应商的总账单=数量*价格
                numbers.add(money); // 查每年的总账单，存入数组中 [number1,number2,number3,number4,number5]
            }
            //  将供应商名称和这个供应商每年的总账单以键值对的形式存储在map集合中 供应商1:[number1,number2,number3,number4,number5]
            supNameYear.put(supName,numbers);
        }

        map.put("supNameYear",supNameYear);// {java:[],web:[]}
        return map;
    }


    public Map<String, Object> getOutportLineData() {

        // 折线图 用Map集合封装数据
        HashMap<String, Object> map = new HashMap<String, Object>();

        // 取year
        List<String> years = echartsMapper.getYear();
        // 将取到的year存入map
        map.put("years",years);

        // 取agentNames
        List<String> agentNames = echartsMapper.getAgentName();
        // 将取到的agentNames存入map
        map.put("agentNames",agentNames);

        // 取agentName_year
        HashMap<String, Object> agentNameYear = new HashMap<String, Object>();
        for (String agentName : agentNames) {  //代理商1 代理商2 代理商3 。。。。。
            ArrayList<Double> numbers = new ArrayList<Double>();
            for (String year : years) {  // 2019  2020 2021 2022 2023
                Double money =   echartsMapper.getOutportTotolMoney(agentName,year);// 查year年xx供应商的总账单=数量*价格
                numbers.add(money); // 查每年的总账单，存入数组中 [number1,number2,number3,number4,number5]
            }
            //  将供应商名称和这个供应商每年的总账单以键值对的形式存储在map集合中 供应商1:[number1,number2,number3,number4,number5]
            agentNameYear.put(agentName,numbers);
        }

        map.put("agentNameYear",agentNameYear);// {java:[],web:[]}
        return map;
    }
}

